#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long long int64;

int	g[1001][1001];
int	x[1001][1001];
int	y[1001][1001];
int xc[1001], yc[1001];

int	main()
{
	int T;
	cin >> T;

	int n, X, Y;
	while (T--)
	{
		cin >> n >> X >> Y;
		memset(g, 0, sizeof(g));
		for (int i = 0; i < n; ++i)
		{
			int x, y, c;
			cin >> x >> y >> c;
			g[y][x] = g[x][y] = c;
		}

		memset(xc, 0, sizeof(xc));
		memset(yc, 0, sizeof(yc));

		for (int i = 1; i <= X; ++i)
			for (int j = 1; j <= Y; ++j)
			{
				g[i][j] = max(g[i][j], g[i - 1][j]);
				g[i][j] = max(g[i][j], g[i][j - 1]);
				for (int k = 0; k < yc[j]; ++k) 
					g[i][j] = max(g[i][j], g[y[j][k]][j] + g[i - y[j][k]][j]);
				for (int k = 0; k < xc[i]; ++k) 
					g[i][j] = max(g[i][j], g[i][x[i][k]] + g[i][j - x[i][k]]);

				if (g[i][j] > g[i][j - 1]) x[i][xc[i]++] = j;
				if (g[i][j] > g[i - 1][j]) y[j][yc[j]++] = i;
//				printf("[%d, %d] = %d\n", i, j, g[i][j]);
			}
		cout << g[X][Y] << endl;
	}
	return 0;
}
